package com.crazyhat.crazyhat.dto;

import java.time.LocalDateTime;

import org.hibernate.validator.constraints.URL;

import com.baomidou.mybatisplus.annotation.TableField;
import com.crazyhat.crazyhat.anno.SensitiveWordAnno;
import com.crazyhat.crazyhat.attribute.GenderEnum;
import com.crazyhat.crazyhat.entity.Post;
import com.crazyhat.crazyhat.entity.User;
import com.fasterxml.jackson.annotation.JsonFormat;

import jakarta.validation.constraints.NotEmpty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 动态传输对象
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class PostDTO {
    
    /**
     * 动态ID
     */
    private Integer postId;

    /**
     * 社团ID
     */
    private Integer clubId;

    /**
     * 学号
     */
    private Integer studentId;

    /**
     * 发布时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime publishTime;

    /**
     * 标题
     */
    @NotEmpty
    private String title;

    /**
     * 内容
     */
    @NotEmpty
    private String postContent;

    /**
     * 姓名
     */
    @SensitiveWordAnno
    private String name;

    /**
     * 性别
     */
    private GenderEnum gender;

    /**
     * 头像地址
     */
    @URL
    private String avatarUrl;

    public boolean initByPost(Post post) {
        if (post==null) {
            return false; 
        }

        this.postId = post.getPostId();
        this.clubId = post.getClubId();
        this.studentId = post.getStudentId();
        this.publishTime = post.getPublishTime();
        this.title = post.getTitle();
        this.postContent = post.getPostContent();

        return true;
    }

    public boolean initByUser(User user) {
        if (user==null) {
            return false; 
        }

        this.name = user.getName();
        this.gender = user.getGender();
        this.avatarUrl = user.getAvatarUrl();

        return true;
    }
}
